<?php
/* this class is for admin section */
/* link admin */
class Admin extends CI_Controller{

	function __construct(){
		parent::__construct();
		$this->load->model('admin_m');
		$this->load->model('visitors_m');
		$this->load->model('clients_m');
		$this->load->model('advertise_m');
		if($this->session->userdata('admin_id') == false){
			redirect('login/admin');
		}
	}// end construct..
	function index(){
		
		$admin = $this->admin_m->get_admin_info($this->session->userdata('admin_id'));
		$visitors = $this->visitors_m->get_visitors();
		$clients = $this->clients_m->get_clients();
		$adds = $this->advertise_m->get_data();
		$data = array(
			'title'=>'Admin | Home',
			'admin' => $admin,
			'visitors' => $visitors,
			'clients' => $clients,
			'adds' => $adds
		);
		$this->load->view("admin/includes/header",$data);
		$this->load->view("admin/home",$data);
		$this->load->view("admin/includes/footer");
		
	}// end admin function	
	function logout(){
		$this->session->sess_destroy();
		redirect('login/admin');
	}
	function advertisement(){
	
		$action = $this->uri->segment(3);
		$admin = $this->admin_m->get_admin_info($this->session->userdata('admin_id'));
		$ad = $this->advertise_m->get_data();
		
		if($action == 'save'){
			$res_ads = $this->advertise_m->save_ads();
			if($res_ads) redirect('admin/advertisement');
		}
	
		
		$data = array(
			'title'=>'Admin | Advertisements ',
			'admin' => $admin,
			'ad' => $ad
			
		);
		$this->load->view("admin/includes/header",$data);
		
		if($action == false){
			$this->load->view("admin/adds/view",$data);
		}
		else if($action == 'add'){
			$this->load->view("admin/adds/add",$data);
		}
		else{
			$this->load->view("admin/adds/view",$data);
		}
		$this->load->view("admin/includes/footer");

	}// end advertisement..
	function profile(){
		$page = $this->uri->segment(2); // page..
		$action = $this->uri->segment(3); // action..
		
		$admin = $this->admin_m->get_admin_info($this->session->userdata('admin_id'));
		$ad = $this->advertise_m->get_data();
		
		$data = array(
			'title'=>'Admin | Advertisements ',
			'admin' => $admin,
			'ad' => $ad
			
		);
		
		if($action == 'edit'){
			$res = $this->admin_m->edit();
			if($res) redirect('admin/profile');
		}// this condition will execute if the action is edit..
		
		$this->load->view("admin/includes/header",$data);
		
		if($page == 'profile'){
			$this->load->view("admin/profile/view",$data);
		}
		else if($action == 'add' && $page == 'profile'){
			$this->load->view("admin/profile/add",$data);
		}
		else{
			$this->load->view("admin/profile/view",$data);
		}
		$this->load->view("admin/includes/footer");
		
		
		
	}// end function profile.. 
}// end class admin..